//------------------------------------------------------------------------------
// <pcdd-entitiy>
//     系统管理业务类库
//     角色业务对象
// </pcdd-entitiy>
//------------------------------------------------------------------------------

using CL.Enum.Common;
using CL.SystemInfo.DAL;
using CL.SystemInfo.Entity;
using CL.Tools.Common;
using System.Collections.Generic;

namespace CL.SystemInfo.BLL
{

    /// <summary>
    /// RosleBLL 业务
    /// </summary>
    public class RosleBLL
    {
        RosleDAL dal = new RosleDAL(DbConnectionEnum.CaileSystem);

        /// <summary>
        /// 插入对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int InsertEntity(RosleEntity entity)
        {
            return dal.InsertEntity(entity);
        }
        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int ModifyEntity(RosleEntity entity)
        {
            try
            {
                bool b = new RosleValueBLL().ModifyRoles(entity.RoleID, entity.manager_role_values);
                if (b)
                    return dal.ModifyEntity(entity);
                return 0;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RosleEntity GetModel(int RoleID)
        {
            return dal.GetModel(RoleID);
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int RoleID)
        {
            return dal.Exists(RoleID);
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int role_id, string nav_name, string action_type)
        {
            RosleEntity model = this.GetModel(role_id);
            if (model != null)
            {
                if (model.RoleType == 1)
                {
                    return true;
                }
                RosleValueEntity modelt = model.manager_role_values.Find(p => p.NavName == nav_name && p.ActionType == action_type);
                if (modelt != null)
                {
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string RoleName)
        {
            return dal.Exists(RoleName);
        }

        /// <summary>
        /// 对象缓存
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RosleEntity GetModelByCache(int id)
        {
            string CacheKey = "CL_RosleModel-" + id;
            object objModel = CacheHelper.Get(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = this.GetModel(id);
                    if (objModel != null)
                    {
                        int ModelCache = ConfigHelper.GetConfigInt("MODELCACHE");
                        CacheHelper.Insert(CacheKey, objModel, ModelCache);
                    }
                }
                catch
                {
                    throw;
                }
            }
            return (RosleEntity)objModel;
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<RosleEntity> GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DelEntity(int id)
        {
            return dal.DelEntity(id);
        }
    }
}
